home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / andere sprachen / gamesmaster / demosrc / julia2.s < prev    next >
Text File  |  1996-07-16  |  8KB  |  358 lines

  1. ;JULIA 2
  2. ;-------
  3. ;A fractal generator, not orginally written by myself but now works with
  4. ;the library.
  5.  
  6.     opt    o+
  7.  
  8.     INCLUDE    "exec/exec_lib.i"
  9.     INCLUDE    "games/games_lib.i"
  10.     INCLUDE    "games/games.i
  11.     INCLUDE    "games/gamesbase.i"
  12.     INCLUDE    "hardware/custom.i"
  13.  
  14. CALL    MACRO
  15.     jsr    _LVO\1(a6)
  16.     ENDM
  17.  
  18. SAVEREGS MACRO
  19.     MOVEM.L    A0-A6/D0-D7,-(SP)
  20.     ENDM
  21.  
  22. RETURNREGS MACRO
  23.     MOVEM.L    (SP)+,A0-A6/D0-D7
  24.     ENDM
  25.  
  26.     SECTION    "Julia",CODE
  27.  
  28. ;==========================================================================;
  29. ;                             INITIALISE DEMO
  30. ;==========================================================================;
  31.  
  32. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  33.     move.l    ($4).w,a6
  34.     lea    GMS_Name(pc),a1
  35.     moveq    #$00,d0
  36.     CALL    OpenLibrary
  37.     move.l    d0,GMS_Base
  38.     beq    Quit
  39.  
  40.     move.l    GMS_Base(pc),a6
  41.     CALL    SetUserPri
  42.  
  43.     move.l    GMS_Base(pc),a6          ;Tell GMS that we want to add a
  44.     lea    ScreenStruct(pc),a0      ;screen for use.
  45.     CALL    Add_Screen
  46.     tst.l    d0
  47.     bne    Error
  48.  
  49.     lea    ScreenStruct(pc),a0      ;Now show the screen/pic.
  50.     CALL    Show_Screen
  51.  
  52. ;==========================================================================;
  53. ;
  54. ;==========================================================================;
  55.  
  56.     lea    DataArea(pc),a5
  57.     move.l    #$fffffffe,(a5)+         ;a5 = $fffffffe+
  58.     move.l    #$80000014,(a5)+         ;a5 = mask & word per raster count
  59.  
  60. StartJulia:
  61.     move.l    ScreenStruct+SS_MemPtr1(pc),a0 ;get pointer to bitplanes
  62.  
  63. .waitb    btst.b    #6,$dff000+dmaconr
  64.     bne.b    .waitb
  65.     move.l    a0,$dff000+bltdpt
  66.     move.l    #$01000000,$dff000+bltcon0
  67.     clr.w    $dff000+bltdmod
  68.     move.w    #(640*64)+40,$dff000+bltsize ;256*40*5 bytes
  69.  
  70.     lea    JuliaData(pc),a6
  71.     move.l    (a6)+,(a5)               ;a5 = ?
  72.  
  73. .JuliaFound
  74.     move.w    (a5),MValue              ;initial m
  75.     move.w    (a6),PixStep             ;pixel step
  76.     move.w    (a6)+,RastStep           ;raster step
  77.     move.l    (a6)+,C1C2               ;initial c1 and c2
  78.     move.w    #256,LinesLeft(a5)       ;vertical height
  79.     lea    256*40(a0),a1
  80.     lea    256*40(a1),a2
  81.     lea    256*40(a2),a3
  82.     lea    $04000000,a6             ;for magnitude test
  83.  
  84.     lea    256*40(a3),a4
  85.  
  86.     MOVE.L    A6,-(SP)
  87.     move.l    GMS_Base(pc),a6
  88.     CALL    Wait_OSVBL
  89.     MOVE.L    (SP)+,A6
  90.  
  91. PixelLoop:
  92.     move.w    (a5),d1                  ;d1 = Initial X
  93.     move.w    InitialY(a5),d0          ;d0 = Initial Y
  94.     moveq    #30,d7                   ;d7 = 30.
  95.     movem.w    C1C2(pc),d4-d5           ;MA : d4/d5 = C1/C2
  96.     move.w    d0,d2                    ;d2 = Initial Y
  97.     move.w    d1,d3                    ;d3 = Initial X
  98.     bra.s    CheckMagnitude
  99.  
  100. IterateJulia:
  101.     sub.l    d3,d2                    ;x^2 - y^2
  102.     lsl.l    #4,d2                    ;fix decimal point
  103.     swap    d2                       ;...
  104.     add.w    d4,d2                    ;x1 = x^2 - y^2 + c1
  105.  
  106.     move.w    d1,d3                    ;y
  107.     muls    d0,d3                    ;x * y
  108.     lsl.l    #5,d3                    ;fix decimal point and multiply by 2
  109.     swap    d3                       ;...
  110.     add.w    d5,d3                    ;y1 = 2 * x * y + c2
  111.  
  112.     move.w    d2,d0                    ;x = x1
  113.     move.w    d3,d1                    ;y = y1
  114.  
  115. CheckMagnitude:
  116.     muls    d2,d2                    ;x^2
  117.     muls    d3,d3                    ;y^2
  118.     move.l    d2,d6
  119.     add.l    d3,d6                    ;z = x^2 + y^2
  120.     cmp.l    a6,d6                    ;escaped yet?
  121.     dbhi    d7,IterateJulia
  122.     move.w    PixelMask(a5),d6
  123.     moveq    #0,d5
  124.     move.b    JumpTable+1(pc,d7.w),d5
  125.     jmp    JumpTable(pc,d5.w)
  126.  
  127. JumpTable:
  128.     dc.b    Plot00-JumpTable,Plot31-JumpTable
  129.     dc.b    Plot30-JumpTable,Plot29-JumpTable
  130.     dc.b    Plot28-JumpTable,Plot27-JumpTable
  131.     dc.b    Plot26-JumpTable,Plot25-JumpTable
  132.     dc.b    Plot24-JumpTable,Plot23-JumpTable
  133.     dc.b    Plot22-JumpTable,Plot21-JumpTable
  134.     dc.b    Plot20-JumpTable,Plot19-JumpTable
  135.     dc.b    Plot18-JumpTable,Plot01-JumpTable
  136.     dc.b    Plot16-JumpTable,Plot15-JumpTable
  137.     dc.b    Plot14-JumpTable,Plot13-JumpTable
  138.     dc.b    Plot12-JumpTable,Plot11-JumpTable
  139.     dc.b    Plot10-JumpTable,Plot09-JumpTable
  140.     dc.b    Plot08-JumpTable,Plot07-JumpTable
  141.     dc.b    Plot06-JumpTable,Plot05-JumpTable
  142.     dc.b    Plot04-JumpTable,Plot03-JumpTable
  143.     dc.b    Plot02-JumpTable,Plot17-JumpTable
  144.  
  145. Plot22:    or.w    d6,(a4)
  146.     or.w    d6,(a2)
  147.     or.w    d6,(a1)
  148.     bra.b    Plot00
  149.  
  150. Plot21:    or.w    d6,(a4)
  151.     or.w    d6,(a2)
  152.     or.w    d6,(a0)
  153.     bra.b    Plot00
  154.  
  155. Plot20:    or.w    d6,(a4)
  156.     or.w    d6,(a2)
  157.     bra.b    Plot00
  158.  
  159. Plot18:    or.w    d6,(a4)
  160.     or.w    d6,(a1)
  161.     bra.b    Plot00
  162.  
  163. Plot26:    or.w    d6,(a4)
  164. Plot10:    or.w    d6,(a3)
  165.     or.w    d6,(a1)
  166.     bra.b    Plot00
  167.  
  168. Plot23:    or.w    d6,(a4)
  169.     or.w    d6,(a2)
  170.     or.w    d6,(a1)
  171.     or.w    d6,(a0)
  172.     bra.b    Plot00
  173.  
  174. Plot19:    or.w    d6,(a4)
  175.     or.w    d6,(a1)
  176.     or.w    d6,(a0)
  177.     bra.b    Plot00
  178.  
  179. Plot27:    or.w    d6,(a4)
  180. Plot11:    or.w    d6,(a3)
  181.     or.w    d6,(a1)
  182.     or.w    d6,(a0)
  183.     bra.b    Plot00
  184.  
  185. Plot17:    or.w    d6,(a4)
  186.     or.w    d6,(a0)
  187.     bra.b    Plot00
  188.  
  189. Plot25:    or.w    d6,(a4)
  190. Plot09:    or.w    d6,(a3)
  191.     or.w    d6,(a0)
  192.     bra.b    Plot00
  193.  
  194. Plot29:    or.w    d6,(a4)
  195. Plot13:    or.w    d6,(a3)
  196. Plot05:    or.w    d6,(a2)
  197.     or.w    d6,(a0)
  198.     bra.b    Plot00
  199.  
  200. Plot16:    or.w    d6,(a4)
  201.     bra.b    Plot00
  202.  
  203. Plot24:    or.w    d6,(a4)
  204. Plot08:    or.w    d6,(a3)
  205.     bra.b    Plot00
  206.  
  207. Plot28:    or.w    d6,(a4)
  208. Plot12:    or.w    d6,(a3)
  209. Plot04:    or.w    d6,(a2)
  210.     bra.b    Plot00
  211.  
  212. Plot30:    or.w    d6,(a4)
  213. Plot14:    or.w    d6,(a3)
  214. Plot06:    or.w    d6,(a2)
  215. Plot02:    or.w    d6,(a1)
  216.     bra.b    Plot00
  217.  
  218. Plot31:    or.w    d6,(a4)
  219. Plot15:    or.w    d6,(a3)
  220. Plot07:    or.w    d6,(a2)
  221. Plot03:    or.w    d6,(a1)
  222. Plot01:    or.w    d6,(a0)
  223.  
  224. Plot00:    MOVE.L    D0,-(SP)
  225.     move.w    PixStep(pc),d0
  226.     add.w    d0,(a5)                  ;pixel "step"
  227.     MOVE.L    (SP)+,D0
  228.  
  229.     ror.w    PixelMask(a5)            ;shift mask over
  230.     bpl.w    PixelLoop
  231.  
  232.     addq.w    #2,a0
  233.     addq.w    #2,a1
  234.     addq.w    #2,a2
  235.     addq.w    #2,a3
  236.     addq.w    #2,a4
  237.     subq.w    #1,WordsInRaster(a5)     ; subtract from word counter
  238.     bne.w    PixelLoop
  239.  
  240.     MOVE.L    A6,-(SP)
  241.     move.l    GMS_Base(pc),a6
  242.     CALL    AutoOSReturn
  243.     MOVE.L    (SP)+,A6
  244.  
  245.     btst.b    #6,$bfe001
  246.     beq.b    Exit
  247.  
  248.     move.w    #320/16,WordsInRaster(a5) ; words per raster
  249.     btst.b    #2,$dff016               ; new julia?
  250.     beq.b    NewJulia
  251.  
  252. RasterInit:
  253.     move.w    MValue(pc),(a5)          ; inital M value
  254. RasterAdd:
  255.     MOVE.L    D0,-(SP)
  256.     move.w    RastStep(pc),d0
  257.     add.w    d0,InitialY(a5)          ; raster "step"
  258.     MOVE.L    (SP)+,D0
  259.     subq.w    #1,LinesLeft(a5)
  260.     bne.w    PixelLoop
  261.  
  262. WaitMouse:
  263.     btst.b    #6,$bfe001
  264.     beq.b    Exit
  265.     btst.b    #2,$dff016
  266.     bne.b    WaitMouse
  267.  
  268. NewJulia:
  269.     btst.b    #2,$dff016
  270.     beq.b    NewJulia
  271.     bra.w    StartJulia
  272.  
  273. ;===========================================================================;
  274. ;                              RETURN TO DOS
  275. ;===========================================================================;
  276.  
  277. Exit:    move.l    GMS_Base(pc),a6
  278.     lea    ScreenStruct(pc),a0
  279.     CALL    Delete_Screen            ;Give back screen memory etc.
  280. Error    move.l    GMS_Base(pc),a1
  281.     move.l    ($4).w,a6
  282.     CALL    CloseLibrary
  283. Quit    MOVEM.L    (SP)+,A0-A6/D1-D7
  284.     moveq    #$00,d0
  285.     rts
  286.  
  287. ;===========================================================================;
  288. ;                                  DATA
  289. ;===========================================================================;
  290.  
  291. MValue:      dc.w    0
  292. PixStep:  dc.w    0
  293. RastStep: dc.w    0
  294. C1C2:      dc.l    0
  295.  
  296. GMS_Name:
  297.     dc.b    "games.library",0
  298.     even
  299. GMS_Base:
  300.     dc.l    0
  301.  
  302. AMT_PLANES =    5
  303.  
  304. ScreenStruct:
  305.     dc.l    "GSV1"
  306.     dc.l    0,0,0                    ;Screen_Mem1/2/3
  307.     dc.l    0                        ;Screen link.
  308.     dc.l    ScreenPalette            ;Address of screen palette.
  309.     dc.l    0                        ;Address of rasterlist.
  310.     dc.l    0                        ;Amt of colours in palette.
  311.     dc.w    256,320,320/8            ;Screen Height, Width, Width/8
  312.     dc.w    256,320,320/8            ;Pic Height, Width, Width/8
  313.     dc.w    AMT_PLANES               ;Amt_Planes
  314.     dc.w    0,0                      ;Top Of Screen, X/Y
  315.     dc.w    0                        ;Scroll buffer in pixels/8.
  316.     dc.w    0,0                      ;X/Y counters (for scrolling).
  317.     dc.l    NOBURST                  ;Special attributes.
  318.     dc.w    LORES                    ;Screen mode.
  319.     dc.b    PLANAR                   ;Screen type
  320.     dc.b    0                        ;Screen Is Being Displayed?
  321.     dc.l    0,0                      ;Reserved area.
  322.     even
  323.  
  324. ScreenPalette:
  325.     dc.w    $0000,$0831,$000e,$000d,$000c,$000b,$000a,$0009
  326.     dc.w    $0008,$0007,$0106,$0205,$0304,$0403,$0502,$0611
  327.     dc.w    $0720,$000f,$0942,$0a53,$0b64,$0c75,$0d86,$0c97
  328.     dc.w    $0ba8,$0a9a,$098b,$0879,$0767,$0555,$0343,$0131
  329.  
  330. JuliaData:
  331.     dc.l    $f800eb00
  332.     dc.w    $0018,$0100,$0ad0,$ec00
  333.     dc.l    $fd21eeae
  334.     dc.w    $0225,$000d,$f420,$fd43
  335.  
  336.  
  337.     dc.l    $ef000010
  338.     dc.w    $0600,$0100,$f226,$fd56
  339.  
  340.     dc.l    $0015ee00
  341.     dc.w    $fb40,$ede2,$f0b2,$001d
  342.  
  343.     dc.l    $05c0ff00
  344.     dc.w    $ef12,$e812,$001d,$f320
  345.     dc.l    $00000000
  346.  
  347.  
  348.     rsset    -4
  349. PixelMask    rs.w   1    ;mask to "OR" with bitplanes
  350. WordsInRaster    rs.w   1    ;number of words left in current raster
  351. InitialX    rs.w   1    ;inital x
  352. InitialY    rs.w   1    ;inital y
  353. LinesLeft    rs.w   1    ;number of lines left to draw
  354.  
  355.     dc.l    0
  356. DataArea:
  357.     ds.b    40
  358.